package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WorkFault;
import com.ruoyi.system.service.IWorkFaultService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障表Controller
 * 
 * @author ruoyi
 * @date 2020-04-20
 */
@Controller
@RequestMapping("/system/fault")
public class WorkFaultController extends BaseController
{
    private String prefix = "system/fault";

    @Autowired
    private IWorkFaultService workFaultService;

    //@RequiresPermissions("system:fault:view")
    @GetMapping()
    public String fault()
    {
        return prefix + "/fault";
    }

    /**
     * 查询故障表列表
     */
    //@RequiresPermissions("system:fault:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WorkFault workFault)
    {
        startPage();
        List<WorkFault> list = workFaultService.selectWorkFaultList(workFault);
        return getDataTable(list);
    }

    /**
     * 导出故障表列表
     */
    //@RequiresPermissions("system:fault:export")
    @Log(title = "故障表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WorkFault workFault)
    {
        List<WorkFault> list = workFaultService.selectWorkFaultList(workFault);
        ExcelUtil<WorkFault> util = new ExcelUtil<WorkFault>(WorkFault.class);
        return util.exportExcel(list, "fault");
    }

    /**
     * 新增故障表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存故障表
     */
    //@RequiresPermissions("system:fault:add")
    @Log(title = "故障表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WorkFault workFault)
    {
        return toAjax(workFaultService.insertWorkFault(workFault));
    }

    /**
     * 修改故障表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WorkFault workFault = workFaultService.selectWorkFaultById(id);
        mmap.put("workFault", workFault);
        return prefix + "/edit";
    }

    /**
     * 修改保存故障表
     */
    //@RequiresPermissions("system:fault:edit")
    @Log(title = "故障表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WorkFault workFault)
    {
        return toAjax(workFaultService.updateWorkFault(workFault));
    }

    /**
     * 删除故障表
     */
    //@RequiresPermissions("system:fault:remove")
    @Log(title = "故障表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(workFaultService.deleteWorkFaultByIds(ids));
    }
}
